{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# MSD 歌曲推荐——数据预处理\n",
    "1. 计算每个用户的总播放次数，找出播放次数最多的用户（最活跃的前800个用户）\n",
    "2. 计算每首歌曲的总播放次数，找出播放次数最多的歌曲（最流行的前800首歌曲）\n",
    "3. 从总数据集中抽取最活跃的前800个用户、最流行的前800首歌曲的播放记录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#coding=utf-8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-09-26T05:34:54.624167Z",
     "start_time": "2017-09-26T05:34:46.420964Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import time\n",
    "\n",
    "#Python SQLITE数据库是一款非常小巧的嵌入式开源数据库软件\n",
    "import sqlite3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 载入原始数据"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Get more information about the Millionsong project from https://labrosa.ee.columbia.edu/millionsong/"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Load Triplets data  [user, song, play_count]\n",
    "#### Get the data from http://labrosa.ee.columbia.edu/millionsong/sites/default/files/challenge/train_triplets.txt.zip"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-09-24T09:48:06.127761Z",
     "start_time": "2017-09-24T09:48:05.969929Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#数据集太大，读10000条记录看看\n",
    "dpath = './data/'\n",
    "df_triplet_dataset = pd.read_csv(filepath_or_buffer = dpath + 'train_triplets.txt', \n",
    "                              nrows=10000,sep='\\t', header=None, \n",
    "                              names=['user','song','play_count'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-09-24T09:48:29.300568Z",
     "start_time": "2017-09-24T09:48:29.275986Z"
    },
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user</th>\n",
       "      <th>song</th>\n",
       "      <th>play_count</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>b80344d063b5ccb3212f76538f3d9e43d87dca9e</td>\n",
       "      <td>SOAKIMP12A8C130995</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>b80344d063b5ccb3212f76538f3d9e43d87dca9e</td>\n",
       "      <td>SOAPDEY12A81C210A9</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>b80344d063b5ccb3212f76538f3d9e43d87dca9e</td>\n",
       "      <td>SOBBMDR12A8C13253B</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>b80344d063b5ccb3212f76538f3d9e43d87dca9e</td>\n",
       "      <td>SOBFNSP12AF72A0E22</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>b80344d063b5ccb3212f76538f3d9e43d87dca9e</td>\n",
       "      <td>SOBFOVM12A58A7D494</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>b80344d063b5ccb3212f76538f3d9e43d87dca9e</td>\n",
       "      <td>SOBNZDC12A6D4FC103</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>b80344d063b5ccb3212f76538f3d9e43d87dca9e</td>\n",
       "      <td>SOBSUJE12A6D4F8CF5</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>b80344d063b5ccb3212f76538f3d9e43d87dca9e</td>\n",
       "      <td>SOBVFZR12A6D4F8AE3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>b80344d063b5ccb3212f76538f3d9e43d87dca9e</td>\n",
       "      <td>SOBXALG12A8C13C108</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>b80344d063b5ccb3212f76538f3d9e43d87dca9e</td>\n",
       "      <td>SOBXHDL12A81C204C0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                       user                song  play_count\n",
       "0  b80344d063b5ccb3212f76538f3d9e43d87dca9e  SOAKIMP12A8C130995           1\n",
       "1  b80344d063b5ccb3212f76538f3d9e43d87dca9e  SOAPDEY12A81C210A9           1\n",
       "2  b80344d063b5ccb3212f76538f3d9e43d87dca9e  SOBBMDR12A8C13253B           2\n",
       "3  b80344d063b5ccb3212f76538f3d9e43d87dca9e  SOBFNSP12AF72A0E22           1\n",
       "4  b80344d063b5ccb3212f76538f3d9e43d87dca9e  SOBFOVM12A58A7D494           1\n",
       "5  b80344d063b5ccb3212f76538f3d9e43d87dca9e  SOBNZDC12A6D4FC103           1\n",
       "6  b80344d063b5ccb3212f76538f3d9e43d87dca9e  SOBSUJE12A6D4F8CF5           2\n",
       "7  b80344d063b5ccb3212f76538f3d9e43d87dca9e  SOBVFZR12A6D4F8AE3           1\n",
       "8  b80344d063b5ccb3212f76538f3d9e43d87dca9e  SOBXALG12A8C13C108           1\n",
       "9  b80344d063b5ccb3212f76538f3d9e43d87dca9e  SOBXHDL12A81C204C0           1"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_triplet_dataset.head(n=10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 计算每个用户的总播放次数 和每首歌曲的播放次数\n",
    "看哪些用户最活跃（play counts最多）\n",
    "由于空间有限，不活跃的用户不考虑了（共有约1M用户）\n",
    "不流行的歌曲也不考虑了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-09-24T10:00:40.238849Z",
     "start_time": "2017-09-24T09:57:54.875213Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "output_dict_users = {} #user及对应的play_count次数集合(在所有的歌曲上求和)\n",
    "output_dict_songs = {} #song及对应的play_count次数集合(在所有的歌曲上求和)\n",
    "\n",
    "#也可以用read_csv\n",
    "with open(dpath + 'train_triplets.txt') as f:\n",
    "    for line_number, line in enumerate(f):\n",
    "        cols = line.strip().split(\"\\t\")\n",
    "        user = cols[0]            #第一列为用户id\n",
    "        song = cols[1]            #第二列为歌曲id\n",
    "        play_count = int(cols[2]) #第三列为播放次数\n",
    "        \n",
    "        if user in output_dict_users:\n",
    "            play_count += output_dict_users[user]\n",
    "        output_dict_users.update({user:play_count})\n",
    "        \n",
    "        if song in output_dict_songs:\n",
    "            play_count += output_dict_songs[song]\n",
    "        output_dict_songs.update({song:play_count})\n",
    "\n",
    "#用户——播放次数列表\n",
    "output_list_users = [{'user':k,'play_count':v} for k,v in output_dict_users.items()]\n",
    "df_users_play_count = pd.DataFrame(output_list_users)\n",
    "\n",
    "#按总播放次数排序\n",
    "df_users_play_count = df_users_play_count.sort_values(by = 'play_count', ascending = False)\n",
    "df_users_play_count.to_csv(path_or_buf= dpath + 'users_playcount.csv', index = False)\n",
    "\n",
    "\n",
    "#歌曲——播放次数列表\n",
    "output_list_songs = [{'song':k,'play_count':v} for k,v in output_dict_songs.items()]\n",
    "df_songs_play_count = pd.DataFrame(output_list_songs)\n",
    "\n",
    "#按总播放次数排序\n",
    "df_songs_play_count = df_songs_play_count.sort_values(by = 'play_count', ascending = False)\n",
    "df_songs_play_count.to_csv(path_or_buf= dpath + 'songs_playcount.csv', index = False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 最活跃的用户和最流行的歌曲"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-09-24T10:08:54.987662Z",
     "start_time": "2017-09-24T10:08:53.518248Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>play_count</th>\n",
       "      <th>user</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>13132</td>\n",
       "      <td>093cb74eb3c517c5179ae24caf0ebec51b24d2a2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>9884</td>\n",
       "      <td>119b7c88d58d0c6eb051365c103da5caf817bea6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>8210</td>\n",
       "      <td>3fa44653315697f42410a30cb766a4eb102080bb</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>7015</td>\n",
       "      <td>a2679496cd0af9779a92a13ff7c6af5c81ea8c7b</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>6494</td>\n",
       "      <td>d7d2d888ae04d16e994d6964214a1de81392ee04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6472</td>\n",
       "      <td>4ae01afa8f2430ea0704d502bc7b57fb52164882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6150</td>\n",
       "      <td>b7c24f770be6b802805ac0e2106624a517643c17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>5656</td>\n",
       "      <td>113255a012b2affeab62607563d03fbdf31b08e7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>5620</td>\n",
       "      <td>6d625c6557df84b60d90426c0116138b617b9449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>5602</td>\n",
       "      <td>99ac3d883681e21ea68071019dba828ce76fe94d</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   play_count                                      user\n",
       "0       13132  093cb74eb3c517c5179ae24caf0ebec51b24d2a2\n",
       "1        9884  119b7c88d58d0c6eb051365c103da5caf817bea6\n",
       "2        8210  3fa44653315697f42410a30cb766a4eb102080bb\n",
       "3        7015  a2679496cd0af9779a92a13ff7c6af5c81ea8c7b\n",
       "4        6494  d7d2d888ae04d16e994d6964214a1de81392ee04\n",
       "5        6472  4ae01afa8f2430ea0704d502bc7b57fb52164882\n",
       "6        6150  b7c24f770be6b802805ac0e2106624a517643c17\n",
       "7        5656  113255a012b2affeab62607563d03fbdf31b08e7\n",
       "8        5620  6d625c6557df84b60d90426c0116138b617b9449\n",
       "9        5602  99ac3d883681e21ea68071019dba828ce76fe94d"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_users_play_count = pd.read_csv(filepath_or_buffer= dpath + 'users_playcount.csv')\n",
    "df_users_play_count.head(n =10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-09-24T10:09:06.800300Z",
     "start_time": "2017-09-24T10:09:06.427869Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>play_count</th>\n",
       "      <th>song</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12466637</td>\n",
       "      <td>SOSXLTC12AF72A7F54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>11290840</td>\n",
       "      <td>SOWCKVR12A8C142411</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>9582939</td>\n",
       "      <td>SOUSMXX12AB0185C24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>9350709</td>\n",
       "      <td>SONYKOW12AB01849C9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>9053507</td>\n",
       "      <td>SOUVTSM12AC468F6A7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>8535928</td>\n",
       "      <td>SOZVCRW12A67ADA0B7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7882419</td>\n",
       "      <td>SOXFPND12AB017C9D1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7875104</td>\n",
       "      <td>SOTWNDJ12A8C143984</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>7318597</td>\n",
       "      <td>SOPUCYA12A8C13A694</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>7317594</td>\n",
       "      <td>SOXWYZP12AF72A42A6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   play_count                song\n",
       "0    12466637  SOSXLTC12AF72A7F54\n",
       "1    11290840  SOWCKVR12A8C142411\n",
       "2     9582939  SOUSMXX12AB0185C24\n",
       "3     9350709  SONYKOW12AB01849C9\n",
       "4     9053507  SOUVTSM12AC468F6A7\n",
       "5     8535928  SOZVCRW12A67ADA0B7\n",
       "6     7882419  SOXFPND12AB017C9D1\n",
       "7     7875104  SOTWNDJ12A8C143984\n",
       "8     7318597  SOPUCYA12A8C13A694\n",
       "9     7317594  SOXWYZP12AF72A42A6"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_songs_play_count = pd.read_csv(filepath_or_buffer= dpath + 'songs_playcount.csv')\n",
    "df_songs_play_count.head(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 从总体数据中抽取子集\n",
    "前800个用户\n",
    "前5000个用户（共1百万用户）的播放次数和占总播放次数的40%（2/8原则：20%的用户播放了80%的次数）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-09-24T10:16:05.763243Z",
     "start_time": "2017-09-24T10:16:05.700186Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.37758555846\n"
     ]
    }
   ],
   "source": [
    "N_SELECTED_USERS = 800\n",
    "N_SELECTED_ITEMS = 800\n",
    "\n",
    "df_users_play_count_subset = df_users_play_count.head(n=N_SELECTED_USERS)\n",
    "\n",
    "n_total_play_count = sum(df_users_play_count.play_count)\n",
    "slected_percent = (float(df_users_play_count_subset.play_count.sum())/n_total_play_count)*100\n",
    "\n",
    "print(slected_percent)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-09-24T10:26:37.537061Z",
     "start_time": "2017-09-24T10:26:37.528055Z"
    }
   },
   "source": [
    "#取800个用户（万分之8的用户）首占总播放次数的1.4%"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-09-24T10:26:38.311410Z",
     "start_time": "2017-09-24T10:26:38.306426Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#共30万首歌曲\n",
    "df_songs_play_count_subset = df_songs_play_count.head(n=N_SELECTED_ITEMS)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-09-24T10:26:39.337554Z",
     "start_time": "2017-09-24T10:26:39.326529Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#前800个用户和800首歌曲\n",
    "users_subset = list(df_users_play_count_subset.user)\n",
    "songs_subset = list(df_songs_play_count_subset.song)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-09-24T10:30:23.563673Z",
     "start_time": "2017-09-24T10:27:22.711377Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#如果机器内存不足，可参考前面逐条读txt文件\n",
    "df_triplet_dataset = pd.read_csv(filepath_or_buffer = dpath + 'train_triplets.txt',sep='\\t', \n",
    "                              header=None, names=['user','song','play_count'])\n",
    "df_triplet_dataset_sub_users = df_triplet_dataset[df_triplet_dataset.user.isin(users_subset) ]\n",
    "del(df_triplet_dataset)\n",
    "\n",
    "df_triplet_dataset_sub_users_songs = df_triplet_dataset_sub_users[df_triplet_dataset_sub_users.song.isin(songs_subset)]\n",
    "del(df_triplet_dataset_sub_users)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(37519, 3)"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_triplet_dataset_sub_users_songs.to_csv(path_or_buf = dpath + 'triplet_dataset_sub.csv', index=False)\n",
    "df_triplet_dataset_sub_users_songs.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "即使这样，还有4万条记录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-09-24T10:33:25.958644Z",
     "start_time": "2017-09-24T10:33:25.939631Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user</th>\n",
       "      <th>song</th>\n",
       "      <th>play_count</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>43812</th>\n",
       "      <td>4e11f45d732f4861772b2906f81a7d384552ad12</td>\n",
       "      <td>SOCKSGZ12A58A7CA4B</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43834</th>\n",
       "      <td>4e11f45d732f4861772b2906f81a7d384552ad12</td>\n",
       "      <td>SOCVTLJ12A6310F0FD</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43863</th>\n",
       "      <td>4e11f45d732f4861772b2906f81a7d384552ad12</td>\n",
       "      <td>SODLLYS12A8C13A96B</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43898</th>\n",
       "      <td>4e11f45d732f4861772b2906f81a7d384552ad12</td>\n",
       "      <td>SOEGIYH12A6D4FC0E3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43961</th>\n",
       "      <td>4e11f45d732f4861772b2906f81a7d384552ad12</td>\n",
       "      <td>SOFRQTD12A81C233C0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44044</th>\n",
       "      <td>4e11f45d732f4861772b2906f81a7d384552ad12</td>\n",
       "      <td>SOHEMBB12A6701E907</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44057</th>\n",
       "      <td>4e11f45d732f4861772b2906f81a7d384552ad12</td>\n",
       "      <td>SOHJOLH12A6310DFE5</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44131</th>\n",
       "      <td>4e11f45d732f4861772b2906f81a7d384552ad12</td>\n",
       "      <td>SOIZLKI12A6D4F7B61</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44146</th>\n",
       "      <td>4e11f45d732f4861772b2906f81a7d384552ad12</td>\n",
       "      <td>SOJGSIO12A8C141DBF</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44187</th>\n",
       "      <td>4e11f45d732f4861772b2906f81a7d384552ad12</td>\n",
       "      <td>SOKEYJQ12A6D4F6132</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                           user                song  \\\n",
       "43812  4e11f45d732f4861772b2906f81a7d384552ad12  SOCKSGZ12A58A7CA4B   \n",
       "43834  4e11f45d732f4861772b2906f81a7d384552ad12  SOCVTLJ12A6310F0FD   \n",
       "43863  4e11f45d732f4861772b2906f81a7d384552ad12  SODLLYS12A8C13A96B   \n",
       "43898  4e11f45d732f4861772b2906f81a7d384552ad12  SOEGIYH12A6D4FC0E3   \n",
       "43961  4e11f45d732f4861772b2906f81a7d384552ad12  SOFRQTD12A81C233C0   \n",
       "44044  4e11f45d732f4861772b2906f81a7d384552ad12  SOHEMBB12A6701E907   \n",
       "44057  4e11f45d732f4861772b2906f81a7d384552ad12  SOHJOLH12A6310DFE5   \n",
       "44131  4e11f45d732f4861772b2906f81a7d384552ad12  SOIZLKI12A6D4F7B61   \n",
       "44146  4e11f45d732f4861772b2906f81a7d384552ad12  SOJGSIO12A8C141DBF   \n",
       "44187  4e11f45d732f4861772b2906f81a7d384552ad12  SOKEYJQ12A6D4F6132   \n",
       "\n",
       "       play_count  \n",
       "43812           1  \n",
       "43834           1  \n",
       "43863           3  \n",
       "43898           1  \n",
       "43961           2  \n",
       "44044           1  \n",
       "44057           1  \n",
       "44131           1  \n",
       "44146           1  \n",
       "44187           1  "
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_triplet_dataset_sub_users_songs.head(n=10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  },
  "toc": {
   "nav_menu": {
    "height": "153px",
    "width": "160px"
   },
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "toc_cell": true,
   "toc_position": {
    "height": "691px",
    "left": "0px",
    "right": "1405px",
    "top": "106px",
    "width": "303px"
   },
   "toc_section_display": "block",
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
